package main

import (
	"fmt"
	"net"
	"os/exec"
	"strings"
)

func getMacAddrs() (macAddrs []string) {
	netInterfaces, err := net.Interfaces()
	if err != nil {
		fmt.Printf("fail to get net interfaces: %v", err)
		return macAddrs
	}

	for _, netInterface := range netInterfaces {
		macAddr := netInterface.HardwareAddr.String()
		if len(macAddr) == 0 {
			continue
		}

		macAddrs = append(macAddrs, macAddr)
	}
	return macAddrs
}

func getIPs() (ips []string) {

	interfaceAddr, err := net.InterfaceAddrs()
	if err != nil {
		fmt.Printf("fail to get net interface addrs: %v", err)
		return ips
	}

	for _, address := range interfaceAddr {
		ipNet, isValidIpNet := address.(*net.IPNet)
		if isValidIpNet && !ipNet.IP.IsLoopback() {
			if ipNet.IP.To4() != nil {
				ips = append(ips, ipNet.IP.String())
			}
		}
	}
	return ips
}
func getIP() (ip string) {
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		fmt.Println(err)
		return
	}
	for _, value := range addrs {
		if ipnet, ok := value.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
			if ipnet.IP.To4() != nil {
				ip = ipnet.IP.String()
				fmt.Println(ipnet.IP.String())
				return
			}
		}
	}
	return
}

func main() {
	//fmt.Printf("mac addrs: %q\n", getMacAddrs())
	//fmt.Printf("ips: %q\n", getIPs())
	//fmt.Printf("ip: %q\n", getIP())
	cmd := exec.Command("ipconfig")
	buf, err := cmd.Output()
	if err != nil {
		//fmt.Println("Error:", err)
		return
	}
	output := string(buf)
	for _, device := range strings.Split(output, "\n") {
		if len(device) > 1 {
			fmt.Println(device)
			//ethHandle, err := ethtool.NewEthtool()
			//if err != nil {
			//	panic(err.Error())
			//}
			//defer ethHandle.Close()
			//stats, err := ethHandle.LinkState(device)
			//if err != nil {
			//	panic(err.Error())
			//}
			//fmt.Printf("LinkName: %s LinkState: %d\n", device, stats)
		}
	}
}
